#ifndef RECPARSER_H
#define RECPARSER_H

#include <QWidget>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QListWidget>
#include <QComboBox>
#include <QCheckBox>
#include <QSpinBox>
#include <QLineEdit>
#include <QPushButton>
#include <QMessageBox>
#include <QByteArrayMatcher>
#include <QtSvg>
#include <QSvgWidget>
#include <QSvgRenderer>
#include <QStandardItemModel>
#include <QListView>

#include "dragwidget.h"


#define MAXFIELDLENGTH 128

class recparser : public QWidget
{
    Q_OBJECT
public:
    recparser(QWidget *parent = 0);
    QByteArray datain;
    QByteArray dataout;
    bool saving;
    QVector<double> pingvalue;

    // LAYOUT
    QListWidget *variablelist;
    QComboBox *variabletype;
    QCheckBox *fixed_length_check;
    QCheckBox *byte_match_check;

    QSpinBox *length_spin;
QLineEdit *byte_array_edit;
QPushButton *add_item_button;
QPushButton *remove_item_button;
QPushButton *save_button;
QTextEdit *testvarstruct;
QPushButton *abcButton;
QPushButton *numButton;
QStandardItemModel *model;
QList<QStandardItem> *modellist;
QListWidget *listview;

enum vartype{BYTE,NUMBER};
enum parsingstate{START,PARSE,VALIDATE};

// Structure for storing variables
struct variable{
    vartype type;
    bool fixed;
    bool matched;
    int length;
    double floatvalue;
    QByteArray matchArray;
};
bool parsing;
bool matching;
int vecIndex;
bool pastdecimal;
bool validVector;
bool spaceOK;
bool periodOK;
bool signOK;
int decimalVal;
unsigned int decimalPlace;
char currentChar;

QList<variable> varVector;

void dataparse(QByteArray);
parsingstate curstate;
QByteArray parsearray;

signals:
    void vectorout(QList<variable>,bool);

public slots:


private:
    QHBoxLayout *mainLayout;
    QVBoxLayout *ctlButtons;

    QHBoxLayout *fixedlengthLayout;
    QVBoxLayout *settingsLayout;
    QVBoxLayout *add_removeLayout;
    QHBoxLayout *bytematchLayout;
    void initLayout();
    void rejectVector(QString);
    void acceptVariable();
    int nextIndex();

private slots:
    void addVariable();
    void removeVariable();
    void savePackage();
    void testVector();

protected:

};

#endif // RECPARSER_H
